<template>
  <div>
    <input placeholder="输入关键字搜索" v-model="uname" @change="fn" />
    <table class="my-table">
      <thead>
        <tr>
          <th>就诊日期</th>
          <th>医生姓名</th>
          <th>诊断结果</th>
          <th>处方信息</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <TableList
          v-for="(item, index) in list"
          :key="index"
          :time="item.time"
          :DoctorName="item.DoctorName"
          :res="item.res"
          :infor="item.infor"
          :operation="item.operation"
        ></TableList>
      </tbody>
    </table>
  </div>
</template>

<script>
import TableList from './components/TableList.vue'

export default {
  components: {
    TableList,
  },

  data() {
    return {
      list: [
        {
          time: '2022-01-03',
          DoctorName: '李四',
          res: '感冒',
          infor: '止疼药',
          operation: '详情',
        },
        {
          time: '2022-03-01',
          DoctorName: '王五',
          res: '腰疼',
          infor: '止疼贴',
          operation: '详情',
        },
        {
          time: '2022-01-01',
          DoctorName: '张三',
          res: '感冒',
          infor: '感冒药',
          operation: '详情',
        },
      ],
      uname: '',
      obj:''
    }
  },

  methods: {
    fn() {
      if (this.uname) {
        this.obj = this.list
        this.list = this.list.filter((item) => {
          return item.DoctorName === this.uname
        })
      } else {
        // alert('名字不能为空')
        this.list = this.obj
      }
    },
  },
}
</script>

<style scoped>
.my-table {
  border-collapse: collapse;
  width: 100%;
}

.my-table td,
.my-table th {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
}

.my-table th {
  background-color: #f2f2f2;
}
</style>
